<?php
namespace Home\Controller;

use Home\Model\ExpenseScheduleModel;
use Home\Model\ApplicationFormModel;

class ExpenseScheduleController extends CommonController{
	
	protected $table="expense_schedule";
  	
  protected $pageSize = 8;
  
  
  public function index(){
 		
		$this->assign('expense_type', $this->M->getExpenseType());
		$this->assign('belongsDepartment',D('ApplicationForm')->getSelfDepartments());
		$this->assign('departName',D('ApplicationForm')->getSelfDepartment());
    $this->display();

  }
 
	public function getList(){
		$this->setQeuryCondition();
	    $count = (int)$this->M->count();
	    $this->setQeuryCondition();
	    $list = $this->M->page(I('get.p',0). ','. $this->pageSize)->order('id desc')->select();
	    
	    $result = array('list'=>$list, 'count'=>$count);
		$this->ajaxReturn($result);

	}
  
  
  //设置查询
  public function setQeuryCondition(){

	if (I('get.expense_type')) {
		$this->M->where(array("expense_type"=> array('EQ', I('get.expense_type'))));
	}
	
	
	if (isset($_GET['belongs_department'])) {
		$this->M->where(array("belongs_department"=> array('EQ', I('get.belongs_department'))));
	}else{
		$this->M->where(array("belongs_department"=> array('EQ', D('ApplicationForm')->getSelfDepartment())));
	}
	
	
	if (I('get.cashier')) {
		$this->M->where(array("cashier"=> array('like', "%".I('get.cashier')."%")));
	}
	
	if (I('get.re_time')) {
		$this->M->where(array("re_time"=> array('like', "%".I('get.re_time')."%")));
	}
	
    $this->M->where( array('info_status'=>array('EQ', 1) ) );

  }

	public function add() {
	  $_POST['belongs_department'] = D('ApplicationForm')->getSelfDepartment();
	  
	  	if (!empty($_POST) && $this->M->create($_POST, 1) && $this->M->add()) {
		  $this->success(L('ADD_SUCCESS'));
	    } else {
		  $this->error($this->M->getError());
	    }
	  
	}


























}